package com.niiwoo.civet.user.service.local.sms.impl;

import com.niiwoo.civet.user.dto.request.RefreshSMSCodeRequestDTO;
import com.niiwoo.civet.user.enums.UserSMSTypeEnum;
import com.niiwoo.civet.user.service.local.UserLoginAccountService;
import com.niiwoo.civet.user.service.local.sms.LimitedSMSSender;
import com.niiwoo.tripod.base.component.PrivacyMasks;
import com.niiwoo.tripod.provider.exception.BizException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * Created by HuangMin on 2018/4/18.
 */
@Component
public class NewMobileNoSMSSender extends LimitedSMSSender {

    @Autowired
    UserLoginAccountService userLoginAccountService;

    @Autowired
    PrivacyMasks privacyMasks;

    @Override
    protected void innerBeforeSend(RefreshSMSCodeRequestDTO requestDTO) {
        if (userLoginAccountService.isExists(privacyMasks.encryptPrivacy(requestDTO.getLoginMobileNo()))) {
            throw new BizException("USR10036");
        }
    }

    @Override
    protected String innerContentTemplate() {
        return CHANGE_MOBILE_TEMPLATE;
    }

    @Override
    protected UserSMSTypeEnum getType() {
        return UserSMSTypeEnum.NEW_CHANGE_MOBILE_NO;
    }

}
